import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rembercount/bings/appBings.dart';
import 'package:rembercount/controller/authLoginController.dart';
import 'package:rembercount/controller/countController.dart';
import 'package:rembercount/controller/themeController.dart';
import 'package:rembercount/controller/categoryController.dart';
import 'package:rembercount/router/appRouter.dart';
import 'package:rembercount/router/appMiddleware.dart';
import 'package:rembercount/config.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // 按顺序初始化控制器
  final authController = Get.put(Authlogincontroller());
  await authController.init(); // 等待登录状态初始化完成
  Get.put(CountController());
  Get.put(ThemeController());
  Get.put(CategoryController());
  
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({super.key});
  final dio = Dio(BaseOptions(baseUrl: Config.baseUrl));
  
  @override
  Widget build(BuildContext context) {
    final authController = Get.find<Authlogincontroller>();
    final themeController = Get.find<ThemeController>();
    
    return GetMaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: themeController.themeColor,
          secondary: themeController.themeColor.withOpacity(0.7),
        ),
        useMaterial3: true,
      ),
      initialBinding: Appbings(),
      initialRoute: authController.isLogin.value ? '/mainpage' : '/login',
      getPages: AppRouter.routes,
    );
  }
}




  

